package com.cyk.comicforumjava.demos.web;

import com.cyk.comicforumjava.demos.base.ResponseResult;
import com.cyk.comicforumjava.demos.dto.UserDto;
import com.cyk.comicforumjava.demos.enits.User;
import com.cyk.comicforumjava.demos.service.LoginService;
import com.cyk.comicforumjava.demos.vo.LoginVo;
import com.qiniu.api.auth.AuthException;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private LoginService loginService;
    @PostMapping("/login")
    public ResponseResult<LoginVo> login( @RequestBody UserDto userDto){
        ResponseResult<LoginVo>result=loginService.login(userDto);
        return result;
    }
    @PostMapping("/register")
    public ResponseResult<String> register(@RequestBody UserDto userDto){
        ResponseResult<String>result=loginService.register(userDto);
        return result;
    }
    @PostMapping("/getUser")
    public ResponseResult<User> getUser(@RequestBody UserDto userDto){
        ResponseResult<User>result=loginService.getUser(userDto);
        return result;
    }
    @PostMapping("getQiniuToken")
    public ResponseResult<String> getQinuToken(@RequestBody UserDto userDto) throws AuthException, JSONException {
        ResponseResult<String>result=loginService.getQiniuToken(userDto);
        return result;
    }
    @PostMapping("/changeAvater")
    public ResponseResult<String> changeAvater(@RequestBody User user) throws UnsupportedEncodingException {
        ResponseResult<String>result=loginService.changeAvater(user);
        return result;
    }
    @PostMapping("/updateSignature")
    public ResponseResult<String> updateSignature(@RequestBody User user){
        ResponseResult<String>result=loginService.updateSignature(user);
        return result;
    }

    @PostMapping("/confirmCode")
        public ResponseResult confirmCode(@RequestBody UserDto userDto) throws Exception {
            ResponseResult result=loginService.confirmCode(userDto);
            return result;
        }

    @PostMapping("/changePassword")
    public ResponseResult changePassword(@RequestBody UserDto userDto){
        ResponseResult result=loginService.changePassword(userDto);
        return result;
    }

}
